package cn.xdd.dbutil;

import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @author user_xdd
 * @Date 2022-04-06 13:37
 * @description
 * @return
 */
public class tesy {

    public static final String DRIVER = "com.mysql.jdbc.Driver";
    public static final String URL = "jdbc:mysql://115.29.209.196:3306/bookmanage2";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "Jiansheyin1";
    /*
     * 创建连接池BasicDataSource
     */
    public static BasicDataSource dataSource = new BasicDataSource();
    public static int size =1;
    //静态代码块
    static {
//对连接池对象 进行基本的配置
        dataSource.setDriverClassName(DRIVER); // 这是要连接的数据库的驱动
        dataSource.setUrl(URL); //指定要连接的数据库地址
        dataSource.setUsername(USERNAME); //指定要连接数据的用户名
        dataSource.setPassword(PASSWORD); //指定要连接数据的密码
        dataSource.setInitialSize(4);


    }

    /*
     * 返回连接池对象
     */
    public static DataSource getDataSource() {
        System.out.println(size);
        size++;
        return dataSource;
    }

}
